package store.lunangangster.bpmn.converter.parser;

import javax.xml.stream.XMLStreamReader;
import org.apache.commons.lang3.StringUtils;
import store.lunangangster.bpmn.constant.BpmnXmlConstant;
import store.lunangangster.bpmn.model.BpmnModel;
import store.lunangangster.bpmn.model.Message;

public class MessageParser implements BpmnXmlConstant {

  public Message parse(XMLStreamReader xsr, BpmnModel bpmnModel) throws Exception {
    Message message = null;

    String messageId = xsr.getAttributeValue(null, ATTRIBUTE_COMMON_ID);
    if (StringUtils.isNotBlank(messageId)) {
      message = new Message();
      message.setId(messageId);
      message.setName(xsr.getAttributeValue(null, ATTRIBUTE_COMMON_NAME));
      bpmnModel.addToElementMap(message);
    }

    return message;
  }
}
